#include "get_arg.h"


#include <boost/program_options/options_description.hpp>
#include <boost/program_options.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/lexical_cast.hpp>
// link with -lboost_filesystem-gcc -lboost_program_options-gcc
// program_options_helper.cpp


#include <iostream>
#include <string>
#include <set>
#include <cmath>




// my functions
#define DEBUG_LEVEL 6
#include <debug_func.h>
#include <ultoa.h>
#include <print_error.h>
#include <stdexcept>
#include <program_options_helper.h>

using std::string;
using std::cerr;
using std::ofstream;
using std::cerr;
using std::cout;
using boost::filesystem::path;
using boost::filesystem::extension;
using boost::filesystem::basename;
using boost::lexical_cast;


using namespace program_options_helper;
namespace po = boost::program_options_lg;

//_______________________________________________________________________________________

//		process_command_line_options

//				from command line
//				Created [9/13/2001]

//_______________________________________________________________________________________
bool process_command_line_options(int argc, char* argv[], t_program_args& args)
{

	// mandatory arguments
//	string matrix_file_name;
//	po::options_description mandatory_args("Mandatory Arguments");
//	mandatory_args.add_options()

	args.optional_args.add_options()
	("leaf_number_max,l", po::value<unsigned>(&args.node_limit)
											->set_name("COUNT")
											->default_value(50),
										"Extract branches with fewer than COUNT "
										"number of leaves.")
	("branch_length_limit,b", po::value<float>(&args.len_limit)
											->set_name("LENGTH")
											->default_value(2.5),
										"Extract branches with any leaf to branch "
										"distances longer than LENGTH.");

	args.add_std_options();
	po::options_description all_args("");
	all_args
//			.add(mandatory_args)
			.add(args.optional_args);

	// parse command line
	po::variables_map vm;
	po::store(po::command_line_parser(argc, argv).options(all_args).run(), vm);
	po::notify(vm);

	if (vm.count("version"))
	{
		print_version(cerr, *argv, "1.0\n"
			"\tHistory: \n\n"
			"\tv 1.0\1"
			"Initial version\n"
//			"\tv 1.1\1"
//			"01-02-2005\1"
//			"Split programme so that vanilla version does not do anything with matrices.\n"
			);
		return false;
	}
	if (vm.count("help"))
	{
		string exe_description =
			"Takes New Hampshire trees via STDIN "
			"and extracts all large sub-branches to STDOUT: "
			"those longer than a specified limit but with fewer than a specified "
			"number of leaves.\n";

		print_usage(cerr, *argv, "[OPTIONS] < INPUT.TREES > OUTPUT.TREES",
									all_args, exe_description, 80);
		return false;
	}

	//check_required_options(vm, mandatory_args);




	args.open_err_log();
	return true;
}





